package com.example.sparkdataapi.controller;

import com.example.sparkdataapi.entity.AnalysisResult;
import com.example.sparkdataapi.repository.AnalysisResultRepository;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

@Controller
@RequestMapping("/api/ty")
public class AnalysisResultController {

    @Autowired
    private AnalysisResultRepository repository;

    @GetMapping("/analysis")
    public String getAnalysisResults(Model model) throws JsonProcessingException {
        List<AnalysisResult> analysisResults = repository.findAll();

        model.addAttribute("analysisResults", analysisResults);
        model.addAttribute("serverTime", LocalDateTime.now());
        System.out.println(model);
        return "DataPublish";
    }
}
